package com.sit.estatemanagementserver.controller;

import com.sit.estatemanagementserver.enity.Response;
import com.sit.estatemanagementserver.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class ImageController {

    @Autowired
    private ImageService imageService;

    @PostMapping("/images/upload")
    public Response<?> uploadImage(@RequestParam("image") MultipartFile file, @RequestParam("filename") String newFilename) {
        try {
            imageService.processImageUpload(file, newFilename);
            return Response.success();
        } catch (Exception e) {
            return Response.error("图片上传失败: " + e.getMessage());
        }
    }
}